// VideoFrameView.cpp : implementation file
//

#pragma once
#include "stdafx.h"
#include "NC_AVBPlayer.h"
#include "VideoFrameView.h"

// #include "ffmpegh264decoder.cpp"
// #include "drawer.cpp"


#define RUN_H264FILE_PLAYBACKTEST

//
// Packet Capturer
//
extern int pcaptest_main(void);
extern void filetest_main(void* pParam);



//
// Decoder
//
extern void DecoderInit(int width, int height, void* pParam = NULL);
//extern void DecoderDeinit(void);
extern bool DecoderDecodeBitstream(void* pParam);



//
// Drawer
//
extern void DrawerInit(Drawer* pDrawer);
extern void DrawerDeinit(void);
extern void DrawerDrawFrame(void* pParam = NULL);


static UINT CapturingThread(LPVOID pParam)
{
#ifdef RUN_H264FILE_PLAYBACKTEST
	filetest_main(pParam);
#else
	pcaptest_main();
#endif

	_endthreadex(0);
	return 0;
}


// VideoFrameView

IMPLEMENT_DYNAMIC(VideoFrameView, CWnd)

VideoFrameView::VideoFrameView()
{
	memset((PCAPCapture *) &m_pcapCapture, 0, sizeof(PCAPCapture));
	memset((Drawer *) &m_drawer, 0, sizeof(Drawer));
	m_pSwscale_context = 0;
}

VideoFrameView::~VideoFrameView()
{
}


BEGIN_MESSAGE_MAP(VideoFrameView, CWnd)
END_MESSAGE_MAP()



// VideoFrameView message handlers


void VideoFrameView::PreParation(HDC _hdc) {

	m_drawer.hdcscr = _hdc;
	m_drawer.height = 720;
	m_drawer.width = 1280;

	DecoderInit(m_drawer.height, m_drawer.width, this);
	DrawerInit(&m_drawer);
}


void VideoFrameView::RunningThread(char* pFileName) {
	m_pFileName = pFileName;
	AfxBeginThread(CapturingThread, this);
}